<?php
namespace Framework;
class Session{
    /**
     * @return void
     */
    public static function start()
    {
        if(session_status()== PHP_SESSION_NONE){
            session_start();
        }
    }
    /**
     * @param string
     * @param mixed
     * @return void
     */
    public static function set($key,$value)
    {
        $_SESSION[$key] = $value;
    }
    /**
     * @param string
     * @param mixed
     * @return mixed
     */
    public static function get($key, $default = null)
    {
        return isset($ SEssION[$key])?$_SESSIoN[$key] : $default;
    }
    /**
     * @param string
     * @return bool
     */
    public static function has($key)
    {
        return isset($ SEssIONI[$key]);
    }
    /**
     * @param string
     * @return void
     */
    public static function clear($key)
    {
        if (isset($ SEsSION[$key])){
            unset($_SESSION[$key]);
        }
    }
     /**
     * @return void
     */
    public static function clearAll()
    {
        session_unset();
        session_destroy(); // 销毁会话
    }
     /**
     * @param string
     * @param string
     * @return void
     */
    public static function setFlashMessage($key, $message)
    {
        self::set('flash'.$key,$message);
    }
    /**
     * @param string
     * @param mixed
     * @return string
     */
    public static function getFlashMessage($key, $default = null)
    {
        $message = self::get('flash '.$key, $default);
        self::clear('flash_'. $key);
        return $message;
    }
}